import axios from '../utils/axios'
//请求数据
export const getCartList = async () => {
    const uid = JSON.parse(localStorage.getItem("logindata")||"{}").uid
    const res = await axios.get("/cartlist", { params: { uid } })
    const list = []
    if (res.code === 200) {
        res.list.forEach(item => {
            if (!item.content) return false; item.content.forEach(obj => {
                list.push(obj)
                obj.checked =true
            }
            )
        })
    } return list
}
//计算购物车数量
export const getCartNumber = (cartList) => {
    var number = 0
    cartList.forEach(item => {
        number += item.num
    })
    return number
}
// 请求删除数据接口
export const cartDelete = (id)=> axios.post("/cartdelete",{id})
// 添加数据接口
export const cartAdd = (goodsid,type=1,num=1)=> {
    const uid = JSON.parse(localStorage.getItem("logindata")).uid
    return axios.post("/cartadd",{uid,goodsid,type,num})
}